import { _decorator, Node } from 'cc';
import { BaseLayer } from './BaseLayer';
import { AudioMgr } from '../manager/AudioMgr';
import { ENUM_AUDIO_CLIP, ENUM_UI_LAYER } from '../Enum';
import { Ins } from '../Ins';
import { DataMgr } from '../manager/DataMgr';
const { ccclass, property } = _decorator;

@ccclass('MenuLayer')
export class MenuLayer extends BaseLayer {
    btn_start: Node = null
    btn_setting: Node = null
    btn_rank: Node = null

    onLoad() {
        this.btn_start = this.node.getChildByName('btn_start')
        this.btn_start.on('click', this.onStartClick, this)
        this.btn_setting = this.node.getChildByName('btn_setting')
        this.btn_setting.on('click', this.onSettingClick, this)
        this.btn_rank = this.node.getChildByName('btn_rank')
        this.btn_rank.on('click', this.onRankClick, this)
    }

    onDestroy() {
        this.btn_start.off('click', this.onStartClick, this)
        this.btn_setting.off('click', this.onSettingClick, this)
        this.btn_rank.off('click', this.onRankClick, this)
    }

    async onStartClick() {
        AudioMgr.ins.playSound(ENUM_AUDIO_CLIP.CLICK)
        this.isFade = false
        await Ins.FadeMgr.fadeIn()
        DataMgr.ins.isHard = false
        DataMgr.ins.isResetSkillBtn = true
        Ins.UIMgr.toggle(ENUM_UI_LAYER.MENU, false)
        Ins.UIMgr.toggle(ENUM_UI_LAYER.MAIN)
        Ins.GameMgr.onGameStart()
    }

    async onSettingClick() {
        AudioMgr.ins.playSound(ENUM_AUDIO_CLIP.CLICK)
        this.isFade = true
        await Ins.FadeMgr.fadeIn()
        Ins.UIMgr.toggle(ENUM_UI_LAYER.MENU, false)
        Ins.UIMgr.toggle(ENUM_UI_LAYER.SETTING)
    }

    async onRankClick() {
        AudioMgr.ins.playSound(ENUM_AUDIO_CLIP.CLICK)
        this.isFade = true
        await Ins.FadeMgr.fadeIn()
        Ins.UIMgr.toggle(ENUM_UI_LAYER.MENU, false)
        Ins.UIMgr.toggle(ENUM_UI_LAYER.RANK)
    }
}


